package de.fhffm.scs.simulator.data;

import org.apache.commons.lang3.Range;
import org.csstudio.swt.xygraph.dataprovider.ISample;

public class BloodSugarLevel implements Comparable<BloodSugarLevel>, ISample {

	private static final BloodSugarLevel BEGIN_OK = new BloodSugarLevel(70, 0);
	private static final BloodSugarLevel END_OK = new BloodSugarLevel(120, 0);

	private static final BloodSugarLevel MINIMUM = new BloodSugarLevel(
			Integer.MIN_VALUE, 0);
	private static final BloodSugarLevel MAXIMUM = new BloodSugarLevel(
			Integer.MAX_VALUE, 0);

	public static final Range<BloodSugarLevel> OK = Range.between(BEGIN_OK,
			END_OK);

	public static final Range<BloodSugarLevel> HI = Range.between(END_OK,
			MAXIMUM);
	public static final Range<BloodSugarLevel> LO = Range.between(MINIMUM,
			BEGIN_OK);

	private int level;
	private long timestamp;

	public BloodSugarLevel(int level, long timestamp) {
		super();
		this.level = level;
		this.timestamp = timestamp;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	@Override
	public String toString() {
		return "BloodSugarLevel [level=" + level + ", timestamp=" + timestamp
				+ "]";
	}

	@Override
	public int compareTo(BloodSugarLevel o) {
		if (level > o.level) {
			return 1;
		} else if (level < o.level) {
			return -1;
		} else {
			return 0;
		}
	}

	public boolean equals(Object other) {
		if (other instanceof BloodSugarLevel) {
			BloodSugarLevel otherLevel = (BloodSugarLevel) other;
			return level == otherLevel.getLevel()
					&& timestamp == otherLevel.getTimestamp();
		} else {
			return false;
		}
	}

	@Override
	public String getInfo() {
		return null;
	}

	@Override
	public double getXMinusError() {
		return 0;
	}

	@Override
	public double getXPlusError() {
		return 0;
	}

	@Override
	public double getXValue() {
		return getTimestamp();
	}

	@Override
	public double getYMinusError() {
		return 0;
	}

	@Override
	public double getYPlusError() {
		return 0;
	}

	@Override
	public double getYValue() {
		return getLevel();
	}

}
